package com.example.mr5.mygame.main.ad;

import android.app.Activity;

import android.os.Bundle;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.example.mr5.mygame.R;

import java.util.List;

import cn.waps.AdInfo;
import cn.waps.AppConnect;
import cn.waps.AppListener;
import cn.waps.UpdatePointsListener;

public class AdAcitivty extends Activity implements UpdatePointsListener, View.OnClickListener {
    private ImageView barBack;
    private TextView barTitle;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
        setContentView(R.layout.activity_ad);
        getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.bar);

        AppConnect.getInstance("95cec2974bd7db4551fc275772d992a9", "default", this);
////
//        AppConnect.getInstance(this).initPopAd(this);
//        // 设置插屏广告无数据时的回调监听（该方法必须在showPopAd之前调用）
//        AppConnect.getInstance(this).setPopAdNoDataListener(new AppListener() {
//            @Override
//            public void onPopNoData() {
//                Log.i("debug", "插屏广告暂无可用数据");
//            }
//        });
//        // 显示插屏广告
//        AppConnect.getInstance(this).showPopAd(this);

////
//        AppConnect.getInstance(this).initAdInfo();
//        AdInfo adInfo = AppConnect.getInstance(this).getAdInfo();//每次调用将自动轮换广告
//        List<AdInfo> adInfoList = AppConnect.getInstance(this).getAdInfoList();
//        if(adInfoList!=null){
//            Toast.makeText(this, adInfoList.get(0).getAdId() + adInfoList.get(0).getAdText(), Toast.LENGTH_LONG).show();
//        }else Toast.makeText(this, "null", Toast.LENGTH_LONG).show();
        barBack = (ImageView) findViewById(R.id.header_left_btn);
        barBack.setOnClickListener(this);
        barTitle = (TextView) findViewById(R.id.header_text);
        barTitle.setText(getTitle());

        LinearLayout adlayout1 = (LinearLayout) findViewById(R.id.AdLinearLayout1);
        AppConnect.getInstance(this).showBannerAd(this, adlayout1);
        LinearLayout adlayout2 = (LinearLayout) findViewById(R.id.AdLinearLayout2);
        AppConnect.getInstance(this).showBannerAd(this, adlayout2);
//        AppConnect.getInstance(this).clickAd(this, adInfo.getAdId());
//        当用户确认要下载广告应用时，启动下载（仅适用于应用下载类广告）
//        AppConnect.getInstance(this).downloadAd(this, adInfo.getAdId());
//
//        LinearLayout adlayout = new LinearLayout(this);
//        adlayout.setGravity(Gravity.CENTER_HORIZONTAL);
//        RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
//        AppConnect.getInstance(this).showBannerAd(this, adlayout);
//        layoutParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
//        this.addContentView(adlayout, layoutParams);
    }

    @Override
    public void getUpdatePoints(String s, int i) {
        Log.e("aaa", s + "vv" + i);
    }

    @Override
    public void getUpdatePointsFailed(String s) {
        Log.e("aaaddd", s + "vvvv");
    }

    @Override
    public void onClick(View v) {
        if (v.getId() == R.id.header_left_btn) {
            finish();
        }
    }
}
